Thread: error: expected identifier or ‘(’ before ‘{’ token '{ '

  1. #1
    Registered User
    Join Date
    Aug 2015
    Posts
    6

    error: expected identifier or ‘(’ before ‘{’ token '{ '

    I can't figure out why my code will not compile.
    The error listed above is the only error shown on the terminal.
    I have tried taking the ';' after the main(void) statement (as suggested on similar posts) but this just leads to more compilation errors.
    Does anybody have any ideas???

    Code:
    #include <stdio.h>
    
    
    int main(void);
    {
    double change ; 
    int quater =0 , dime =0 , nickel =0 , penny =0 ;
    printf("how much change is owed?\n");
    scanf("%lf" , &change);
    do
    {
        if (change >= 0.25);
        {
        quarter = quarter++ ;
        change = (change - 0.25);
        }
        else if (0.25 > change >= 0.1);
        {
        dime = dime++ ;
        change = (change - 0.1);
        }
        else if (0.1 > change >= 0.05);
        {
        nickel = nickel++ ;
        change = (change - 0.05);
        }
        else if (0.05 > change >= 0.01);
        {
        penny = penny++ ;
        change = (change - 0.01);
        }
    }
    while (change > 0);
    printf("the number of quarters is: %f\n" , &quarter);
    printf("the number of dimes is: %f\n" , &dime);
    printf("the number of nickels is: %f\n" , &nickel);
    printf("the number of pennys is: %f\n" , &penny);
    }

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    The semi-colon after "int main(void)" is a mistake. If you read the errors after removing this, they should have described the problem.

    Also, the semi-colons after each "if()" is also wrong.

    Code:
    int quater =0
    
    // ...
    
     quarter = quarter++ ;
    Check your spelling. And the increment can be simplified to just:

    Code:
    quarter++;

  3. #3
    Registered User
    Join Date
    Aug 2015
    Posts
    6
    ah ok good catch, thanks

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I have tried taking the ';' after the main(void) statement (as suggested on similar posts) but this just leads to more compilation errors.
    Then you'll need to deal with those other errors as well (there are quite a few errors in your code). The semicolon is wrong and needs to be removed.

    There are also several warnings that will need to be dealt with. I suggest you start compiling more often and fixing any warnings or errors before proceeding then you won't have so many error/warning messages to deal with at one time.

    Jim
    Last edited by jimblumberg; 08-20-2015 at 09:01 AM.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    596
    Quote Originally Posted by Matticus View Post
    Code:
     quarter = quarter++ ;
    And the increment can be simplified to just:

    Code:
    quarter++;
    It actually needs to be just
    Code:
    quarter++;
    or possibly
    Code:
    quarter = quarter + 1;
    Learned that here myself

    -
    Last edited by megafiddle; 08-21-2015 at 05:22 PM.

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by megafiddle View Post
    It actually needs to be just
    Code:
    quarter++;
    That's what I said

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    596
    Not exactly

    You implied that this would still be permissible:
    Code:
    quarter = quarter++ ;
    It's not.

    -
    Last edited by megafiddle; 08-22-2015 at 04:04 PM.

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by megafiddle View Post
    You implied that this would still be permissible:
    Ah, poor wording on my part. Point well made.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 04-14-2013, 11:15 AM
  2. expected ')' before '*' token error?
    By Draymire in forum C Programming
    Replies: 2
    Last Post: 11-05-2012, 11:28 PM
  3. Error expected '=', ',' ,'asm', 'or' before token '{'
    By tmac619619 in forum C Programming
    Replies: 2
    Last Post: 10-13-2012, 02:33 PM
  4. Replies: 3
    Last Post: 08-21-2012, 11:50 PM
  5. Error: expected identifier or ‘(’ before ‘{’ token
    By jpcanaverde in forum C Programming
    Replies: 66
    Last Post: 06-08-2010, 12:53 PM